#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e5 + 10;
const int B = 500;
const int TB = N / B + 10;

int n, a[N], bel[N], bl[N], br[N], tag[N];
vec pot[TB];

void rebuild(int x) {
	pot[x].clear(); rep(i, bl[x], br[x]) pot[x].eb(a[i]);
	sort(pot[x].begin(), pot[x].end());
}

int c[N];

void upd(int x, int y, int c) {
	if(bel[x] == bel[y]) { rep(i, x, y) a[i] += c; rebuild(bel[x]); }
	else {
		rep(i, x, br[bel[x]]) a[i] += c;
		rep(i, bl[bel[y]], y) a[i] += c;
		rep(i, bel[x] + 1, bel[y] - 1) tag[i] += c;
		rebuild(bel[x]), rebuild(bel[y]);
	}
}

int query(int x, int y, int lim) {
	int ans = -1;
	auto up = [&](int val) { if(val < lim) chkmax(ans, val); };
	if(bel[x] == bel[y]) {
		rep(i, x, y) up(a[i] + tag[bel[x]]);
		return ans;
	}
	rep(i, x, br[bel[x]]) up(a[i] + tag[bel[x]]); 
	rep(i, bl[bel[y]], y) up(a[i] + tag[bel[y]]); 
	auto tquery = [&](int x, int lim) {
		int t = lower_bound(pot[x].begin(), pot[x].end(), lim - tag[x]) - pot[x].begin();
		t--; if(t >= 0) up(pot[x][t] + tag[x]);
	};
	rep(i, bel[x] + 1, bel[y] - 1) tquery(i, lim);
	return ans;
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in;
	rep(i, 1, n) {
		a[i] = in;
		bel[i] = (i - 1) / B + 1;
	}
	rep(i, 1, n) {
		if(!bl[bel[i]]) bl[bel[i]] = i;
		br[bel[i]] = i;
	}
	rep(i, 1, bel[n]) rebuild(i);
	rep(i, 1, n) {
		int op = in, l = in, r = in, c = in;
		if(op == 0) upd(l, r, c);
		else printf("%d\n", query(l, r, c));
	}
	return 0;
}
